<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.thymeleaf.org/shiro">
<head>
    <th:block th:include="include :: header('质检列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>合作公司：</label>
                            <input type="text" name="cooperationName"/>
                        </li>
                        <li>
                            <label>商品名称：</label>
                            <input type="text" name="commodityName"/>
                        </li>
                        <li>
                            <label>质检状态：</label>
                            <select name="inspectionStatus" th:with="type=${@dict.getType('inspection_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var prefix = ctx + "chain/purchase";
    var inspectionStatusDatas = [[${@dict.getType('inspection_status')}]];

    queryParams = function (params) {
        var search = {};
        $.each($("#formId").serializeArray(), function (i, field) {
            search[field.name] = field.value;
        });
        search.transportStatus = 4; // 只显示已送达
        search.pageSize = params.limit;
        search.pageNum = params.offset / params.limit + 1;
        return search;
    }

    $(function () {
        var options = {
            url: prefix + "/list",
            queryParams: queryParams,
            columns: [
                {checkbox: true},
                {field: 'id', title: '主键', visible: false},
                {field: 'cooperationName', title: '合作公司'},
                {field: 'commodityName', title: '商品名称'},
                {field: 'quantity', title: '采购数量'},
                {
                    field: 'qualifiedQuantity',
                    title: '合格数量',
                    formatter: function(value, row) {
                        return value || '待填写';
                    }
                },
                {
                    field: 'inspectionStatus',
                    title: '质检状态',
                    formatter: function (value) {
                        return $.table.selectDictLabel(inspectionStatusDatas, value);
                    }
                },
                {
                    title: '操作',
                    formatter: function (value, row) {
                        if (row.inspectionStatus == 0) { // 只显示未质检的
                            return '<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="openInspect(\''+row.id+'\')">质检</a>';
                        }
                        return '已处理';
                    }
                }
            ]
        };
        $.table.init(options);
    });

    function openInspect(id) {
        $.modal.open("商品质检", prefix + "/inspect/" + id);
    }
</script>
</body>
</html>
